package com.ruoyi.admin.service.impl;


import com.ruoyi.admin.mapper.DifyDataSourceMapper;
import com.ruoyi.admin.service.IDifyDataSourceService;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


@Service
public class DifyDataSourceService implements IDifyDataSourceService {

    @Resource
    private DifyDataSourceMapper difyDataSourceMapper;

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> getAllMessage(int pageSize, int pageNum, int userId, String query,String  startTime,String endTime) {
        return difyDataSourceMapper.getAllMessage(pageSize, pageNum, userId, query,startTime,endTime);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int getCount(String query,String  startTime,String endTime) {
        return difyDataSourceMapper.getCount(query,startTime,endTime);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> getMessage(String conversation_id) {
        return difyDataSourceMapper.getMessage(conversation_id);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> getMessageNode(String messageId) {
        return difyDataSourceMapper.getMessageNode(messageId);
    }

    @Override
    public List<Map<String, Object>> getContent(String knowledgeIds) {

        if (StringUtils.isBlank(knowledgeIds)) {

            return new ArrayList<>();
        }
        return difyDataSourceMapper.getContent(Arrays.asList(knowledgeIds.split(",")));
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> getAllUserMessageContent(String token, String keywords) {
        return difyDataSourceMapper.getAllUserMessageContent(token, keywords);
    }


    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> getDifyConversationMessage(String token, String conversationId) {
        return difyDataSourceMapper.getDifyConversationMessage(token, conversationId);
    }
}
